package com.powernode.mapper;

import com.powernode.domain.Sku;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * 单品SKU表 Mapper 接口
 * </p>
 *
 * @author 付作巍
 * @since 2024-08-17
 */
public interface SkuMapper extends BaseMapper<Sku> {
    /**
     * 修该商品sku数据
     * @param skuId 标识
     * @param count 总数
     * @param version 版本
     * @return
     */
    @Update("update sku set stocks = stocks + #{count}, actual_stocks = + #{count},version  = version + 1 where sku_id = #{skuId} and version = #{version} and (actual_stocks = + #{count})>=0")
    Integer updateSkuStock(@Param("skuId") Long skuId, @Param("count") Integer count, @Param("version") Integer version);
}
